﻿using DevExpress.ExpressApp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BasicTutorial.Module.BusinessObjects.Planning;
using DevExpress.ExpressApp.Actions;
using DevExpress.Data.Filtering;

namespace BasicTutorial.Module.Controllers
{
    public class ProjectTaskController:ViewController
    {
        private DevExpress.ExpressApp.Actions.SimpleAction simpleAction1;
        private System.ComponentModel.IContainer components;
    
        public ProjectTaskController()
        {
            TargetObjectType = typeof(ProjectTask);
            TargetViewType = ViewType.Any;

            SimpleAction markCompletedAction = new SimpleAction(this, "MarkCompleted",
                DevExpress.Persistent.Base.PredefinedCategory.RecordEdit)
                {
                    TargetObjectsCriteria = (CriteriaOperator.Parse("Status != ?", ProjectTaskStatus.Completed).ToString()), ConfirmationMessage="Are you sure you want to mark the selected task(s) as 'Completed'?", ImageName = "State_Task_Completed"
                };
            markCompletedAction.Execute += (s, e) => {
                foreach (ProjectTask task in e.SelectedObjects)
                {
                    task.EndDate = DateTime.Now;
                    task.Status = ProjectTaskStatus.Completed;
                    View.ObjectSpace.SetModified(task);
                }
                View.ObjectSpace.CommitChanges();
                View.ObjectSpace.Refresh();
            };
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.simpleAction1 = new DevExpress.ExpressApp.Actions.SimpleAction(this.components);
            // 
            // simpleAction1
            // 
            this.simpleAction1.Caption = null;
            this.simpleAction1.ConfirmationMessage = null;
            this.simpleAction1.Id = "2003dbcd-6ca7-43d5-8f4e-eb7e8319ad0c";
            this.simpleAction1.IsExecuting = false;
            this.simpleAction1.ToolTip = null;

        }

    }
}
